/* Copyright (c) 2016-2020 Enfry Ltd. All Rights Reserved.
 * 
 * This software is the confidential and proprietary information of Enfry. 
 * You shall not disclose such Confidential Information
 * and shall use it only in accordance with the terms of the agreements
 * you entered into with Enfry.
 */
package com.enfry.validation.validators;

import java.util.regex.Pattern;

import org.apache.commons.lang3.StringUtils;

import com.enfry.validation.IValidator;
import com.enfry.validation.config.Rule;

/**
 * 正则匹配
 * @Title com.enfry.validation.validators.MatchValidator
 * @author liulei
 * @date 2016年7月22日
 */
public class MatchValidator implements IValidator {

    @Override
    public boolean execute(Object data, Class<?> type, Object value, Rule rule) {
        if (value == null) return false;
        String regex = rule.getParameter("regex");
        return StringUtils.isBlank(regex) || Pattern.matches(regex, value.toString());
    }
}
